package com.ruoyi.system.wnjk.test.rabbitmq.dead;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.ruoyi.system.wnjk.test.rabbitmq.utils.RabbitMqUtils;

public class Producer {
    private static final String NORMAL_EXCHANGE = "normal_exchange";    // 普通交换机名称

    public static void main(String[] args) throws Exception {
        // 创建channel
//        Channel channel = RabbitMqUtils.getChannel();
        // 声明普通交换机
//        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        // 设置消息到TTL时间为10s=10000ms
//        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();
        // 发送10条消息
//        for (int i = 0; i < 10; i++) {
//            String message = i + "";
//            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", properties, message.getBytes());
//            System.out.println("生产者发送消息：" + message);
//        }

        // 创建channel
        Channel channel = RabbitMqUtils.getChannel();
        // 声明普通交换机
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().build();
        // 发送10条消息
        for (int i = 0; i < 10; i++) {
            String message = i + "";
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan", properties, message.getBytes());
            System.out.println("生产者发送消息：" + message);
        }


    }
}
